<?xml version="1.0" encoding="utf-8" ?>
<rx>
	<macro name="ident" text="[a-zA-Z0-9_]+"/>
	<macro name="esc"><text><![CDATA[(\\x[0-9a-fA-F]{2})|(\\u[0-9a-fA-F]{4})|(\\[^xu])]]></text></macro>
	<macro name="string"><text><![CDATA["(([^"\\])|($(esc)))*"]]></text></macro>
	<macro name="char"><text><![CDATA['(([^'\\])|($(esc)))']]></text></macro>
	
	<macro name="rbracket"><text><![CDATA[\((?<rexpr>(?>\((?<RDEPTH>)|\)(?<-RDEPTH>)|($(string))|($(char))|[^()]?)*(?(RDEPTH)(?!)))\)]]></text></macro>
	<macro name="qbracket"><text><![CDATA[\[(?<qexpr>(?>\[(?<QDEPTH>)|\](?<-QDEPTH>)|($(string))|($(char))|[^\[\]]?)*(?(QDEPTH)(?!)))\]]]></text></macro>
	<macro name="tbracket"><text><![CDATA[\<(?<texpr>(?>\<(?<RDEPTH>)|\>(?<-RDEPTH>)|($(string))|($(char))|[^<>]?)*(?(RDEPTH)(?!)))\>]]></text></macro>
	
	<macro name="type" text="byte|sbyte|int|uint|short|ushort|long|ulong|char|void"/>
	
	<replace rx="true" with="$(name)*" rerun="false">
		<text><![CDATA[(const\s+)?(?<name>$(type))\s*\*(\s+const)?]]></text>
	</replace>
	
	<replace rx="true" text="void\s*\*" with="byte*" rerun="false"/>
	
	<replace rx="true" rerun="true">
		<text><![CDATA[\s*\=\s*$(rbracket)\s*;]]></text>
		<with> = $(rexpr);</with>
	</replace>
	
	<replace rx="true" rerun="true">
		<text><![CDATA[\(\s*$(rbracket)\s*\)]]></text>
		<with>($(rexpr))</with>
	</replace>
	
	<replace rx="true">
		<text><![CDATA[(reinterpret_cast|static_cast)\s*$(tbracket)\s*$(rbracket)]]></text>
		<with>(($(texpr))($(rexpr)))</with>
	</replace>

	<replace rx="true" text="for\s*\(\s*;\s*;\s*\)" with="while (true)"/>
	<replace rx="true" text="while\s*\(\s*1\s*\)" with="while (true)"/>
	
	<!-- trailing spaces -->
	<replace rx="true" rerun="true">
		<text><![CDATA[[\x20\t]*(?<eol>\r?\n)]]></text>
		<with escaped="true">\r\n</with>
	</replace>
	
	<!-- multiple line breaks -->
	<replace rx="true" rerun="true">
		<text><![CDATA[(?<eol>\r?\n\r?\n)(\r?\n)+]]></text>
		<with escaped="true">\r\n\r\n</with>
	</replace>

    <!-- empty braces -->
	<replace rx="true">
		<text>\{\s*\}</text>
		<with>{ /* do nothing */ }</with>
	</replace>
</rx>